package com.aiyige.page.publish.selectinterest.model;

import android.os.Parcel;
import android.os.Parcelable;

import com.aiyige.page.selectinterest.model.IndustryItem;

/**
 * Created by usera on 2017/11/6.
 */

public class PublishInterestItem implements Parcelable {
    public static final int TYPE_SELECT_ALL = 1;
    public static final int TYPE_ADD = 2;
    public static final int TYPE_NORMAL = 3;
    String id;
    String title;
    boolean selected;
    int type;
    PublishIndustryItem parent;

    public PublishInterestItem() {
    }

    private PublishInterestItem(Builder builder) {
        setId(builder.id);
        setTitle(builder.title);
        setSelected(builder.selected);
        setType(builder.type);
        setParent(builder.parent);
    }

    public static Builder newBuilder() {
        return new Builder();
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public boolean isSelected() {
        return selected;
    }

    public void setSelected(boolean selected) {
        this.selected = selected;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public PublishIndustryItem getParent() {
        return parent;
    }

    public void setParent(PublishIndustryItem parent) {
        this.parent = parent;
    }

    public static final class Builder {
        private String id;
        private String title;
        private boolean selected;
        private int type;
        private PublishIndustryItem parent;

        private Builder() {
            id = "";
            title = "";
            selected = false;
            type = TYPE_NORMAL;
            parent = null;
        }

        public Builder id(String id) {
            this.id = id;
            return this;
        }

        public Builder title(String title) {
            this.title = title;
            return this;
        }

        public Builder selected(boolean selected) {
            this.selected = selected;
            return this;
        }

        public Builder type(int type) {
            this.type = type;
            return this;
        }

        public Builder parent(PublishIndustryItem parent) {
            this.parent = parent;
            return this;
        }

        public PublishInterestItem build() {
            return new PublishInterestItem(this);
        }
    }


    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(this.id);
        dest.writeString(this.title);
        dest.writeByte(this.selected ? (byte) 1 : (byte) 0);
        dest.writeInt(this.type);
        dest.writeParcelable(this.parent, flags);
    }

    protected PublishInterestItem(Parcel in) {
        this.id = in.readString();
        this.title = in.readString();
        this.selected = in.readByte() != 0;
        this.type = in.readInt();
        this.parent = in.readParcelable(PublishIndustryItem.class.getClassLoader());
    }

    public static final Creator<PublishInterestItem> CREATOR = new Creator<PublishInterestItem>() {
        @Override
        public PublishInterestItem createFromParcel(Parcel source) {
            return new PublishInterestItem(source);
        }

        @Override
        public PublishInterestItem[] newArray(int size) {
            return new PublishInterestItem[size];
        }
    };
}
